package com.breakfast.fun.ui.user.more;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.breakfast.fun.Constant;
import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseActivity;
import com.breakfast.fun.base.BaseModel;
import com.breakfast.fun.base.BasePresenter;
import com.breakfast.fun.ui.user.feedback.FeedBackActivity;
import com.breakfast.fun.ui.user.help.HelpCenterActivity;
import com.breakfast.fun.ui.web.WebActivity;
import com.breakfast.fun.util.JumpUtil;
import com.breakfast.fun.util.SharedUtil;
import com.breakfast.fun.util.T;
import com.breakfast.fun.view.widget.CustomDialog;
import com.breakfast.fun.view.widget.TitleBarView;

import butterknife.Bind;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.friends.Wechat;

public class MoreActivity extends BaseActivity<BasePresenter, BaseModel> {

    @Bind(R.id.rl_user_more_help)
    RelativeLayout rlUserMoreHelp;
    @Bind(R.id.rl_user_more_invite)
    RelativeLayout rlUserMoreInvite;
    @Bind(R.id.rl_user_more_aboutus)
    RelativeLayout rlUserMoreAboutus;
    @Bind(R.id.tbv_user_more)
    TitleBarView tbvUserMore;
    private CustomDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_user_more;
    }

    @Override
    public void initView() {
        tbvUserMore.setTitleNoRight("更多");
        tbvUserMore.setBack(this);
        rlUserMoreHelp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MoreActivity.this, HelpCenterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        rlUserMoreInvite.setOnClickListener(view -> {
            if (Constant.getUserData() == null) {
                T.show("请登录!");
                JumpUtil.toLogin(this);
                return;
            }
            dialog = new CustomDialog(MoreActivity.this, R.style.dialog_style,
                    R.layout.dialog_custom, "邀请提示", "您的邀请码是：" + SharedUtil.getString(context, "recommendCode") + ",邀请好友成功下单既得5元，是否确定邀请好友?", false, false, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    ShareSDK.initSDK(MoreActivity.this);
                    Platform platform = ShareSDK.getPlatform(Wechat.NAME);
                    showShare(platform.getName());
                }
            });
            dialog.show();
        });
        rlUserMoreAboutus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MoreActivity.this, WebActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("title", "关于我们");
                intent.putExtra("des", "早范,一款专门做早餐的app");
                intent.putExtra("url", "http://mp.weixin.qq.com/s?__biz=MzAwMzcwNDcwOA==&mid=404145494&idx=1&sn=b1c6e493cb9879b53be03390b00def94&scene=4#wechat_redirect");
                startActivity(intent);
            }
        });
    }


    private void showShare(String platform) {
        OnekeyShare oks = new OnekeyShare();

        //关闭sso授权
        //oks.disableSSOWhenAuthorize();

        if (platform != null) {
            oks.setPlatform(platform);
        }
        oks.setSilent(true);
        // 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        // oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle("新用户立享优惠大礼包，早范让吃早餐从将就到讲究");
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl("http://m.52letsgo.com/themes/default/saomiao.php");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("注册时请输出邀请码：" + SharedUtil.getString(context, "recommendCode") + "\n");
        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
        oks.setImageUrl("http://static.52letsgo.cn/zz/ic_share.png");
        /*Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                + context.getResources().getResourcePackageName(R.drawable.ic_share) + "/" +
                context.getResources().getResourceTypeName(R.drawable.ic_share) + "/" +
                context.getResources().getResourceEntryName(R.drawable.ic_share));
        oks.setImagePath(uri.getPath());*/

        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://m.52letsgo.com/themes/default/saomiao.php");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        //oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite("早范邀请码:" + SharedUtil.getString(context, "recommendCode"));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://m.52letsgo.com/themes/default/saomiao.php");

// 启动分享GUI
        oks.show(this);
    }
}
